package com.example.forestmanagement.ui.map;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.example.forestmanagement.R;

import io.openim.android.ouicore.utils.Routes;

@Route(path = Routes.Applet.MAP)
public class MapActivity extends AppCompatActivity {
    private AMap aMap;
    private double lat;
    private double lon;
    private String des;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        Intent intent = getIntent();
        lat = intent.getDoubleExtra("lat", 0);
        lon = intent.getDoubleExtra("lon", 0); // 0 是默认值
        des = intent.getStringExtra("des");

        System.out.println(des);
        ImageView back = findViewById(R.id.back);
        back.setOnClickListener(v -> finish());
        TextView desTv = findViewById(R.id.desTv);
        desTv.setText(des);

        MapView mapView = findViewById(R.id.map_view);
        mapView.onCreate(savedInstanceState);// 此方法必须重写
        aMap = mapView.getMap();
        aMap.setMapType(AMap.MAP_TYPE_SATELLITE);// 卫星地图模式
        addLabelMarker(new LatLng(lat, lon));
    }

    private void addLabelMarker(LatLng position) {

        aMap.addMarker(new MarkerOptions()
                .position(position)
                .icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
                        .decodeResource(getResources(), R.drawable.ic_map_marker)))
                .draggable(true));
        aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, 15));
//        LatLng latLng = new LatLng(39.906901,116.397972);
//        final Marker marker = aMap.addMarker(new MarkerOptions().position(latLng).title("北京").snippet("DefaultMarker"));

    }
}